//
// RS Game Framework
// Copyright © 2009 Jedd Haberstro
// jhaberstro@gmail.com
// 
// $Id:
//

#include "rs/reflection/ReflectionCenter.hpp"
#include "rs/reflection/Class.hpp"

namespace rs
{
    namespace reflection
    {
        ReflectionCenter::~ReflectionCenter() {
        }
        
        void ReflectionCenter::RegisterClass(Class* metaClass) {
            // RS_ASSERTF(classes_.find(CONST_HASH(metaClass->GetName())) == classes_.end(), "ReflectionCenter class name collision: '%s'", metaClass->GetName());
            RS_ASSERT(classIDs_.size() == currentID_, "ReflectionCenter's state is not synced; mismatch between internal currentID_ and length of the ClassContainer");
            RS_ASSERT(classIDs_.find(metaClass->GetName()) == classIDs_.end(), "Class is all ready registered");
            RsSize classid = currentID_++;
            classIDs_[metaClass->GetName()] = classid;
            classes_.push_back(metaClass);
        }
        
        Class const& ReflectionCenter::GetClassRecord(Char8 const* name) const {
            RS_ASSERTF(classIDs_.find(name) != classIDs_.end(), "ReflectionCenter does not contain class '%s'", name);
            Class const& classRecord = *classes_[classIDs_.find(name)->second];
            return classRecord;
        }
        
        Class const& ReflectionCenter::GetClassRecord(RsSize classid) const {
            RS_ASSERTF(classid < classes_.size(), "ReflectionCenter does not contain a class for class-id %i", classid);
            Class const& classRecord = *classes_[classid];
            return classRecord;
        }

        RsSize ReflectionCenter::GetClassID(Char8 const* name) const {
            RS_ASSERTF(classIDs_.find(name) != classIDs_.end(), "ReflectionCenter does not contain class '%s'", name);
            RsSize id = classIDs_.find(name)->second;
            return id;
        }
    }
}